package cn.itcast.bos.web.action.take_delivery;

import cn.itcast.bos.domain.take_delivery.Order;
import cn.itcast.bos.service.take_delivery.OrderService;
import cn.itcast.bos.web.action.common.BaseAction;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.HashMap;

@ParentPackage("json-default")
@Namespace("/")
@Controller
@Scope("prototyoe")
public class OrderAction extends BaseAction<Order> {

    @Autowired
    private OrderService orderService;

    //order_findByOrderNum.action异步请求根据订单号查询订单
    @Action(value = "order_findByOrderNum",results = {@Result(name = "success",type = "json")})
    public String findByOrderNum(){
        Order order = orderService.findByOrderNum(model.getOrderNum());
        HashMap<String, Object> hashMap = new HashMap<>();
        if (order==null){
            //没有订单号
            hashMap.put("success",false);
        }else{
            hashMap.put("success",true);
            hashMap.put("orderData",order);
        }
        ActionContext.getContext().getValueStack().push(hashMap);
        return SUCCESS;
    }
}
